<template>
  <view class="wrap">
    <img class="bg-img" src="https://ainengli.meilianshuke.com/jkhx/raozg/my-center-bg.png" alt="" />
    <view class="header">
      <img
        v-if="patientInfo.gender == 2"
        class="img"
        src="https://ainengli.meilianshuke.com/jkhx/weight/woman.png"
        alt=""
      />
      <img v-else class="img" src="https://ainengli.meilianshuke.com/jkhx/weight/man.png" alt="" />
      <!-- <text v-if="!store.state.userInfo.phone" class="login-text" @tap="auth">登录/注册</text>
      <text v-else-if="!store.state.userInfo.patientInfo" class="login-text" @tap="auth"
        >完善信息</text
      > -->
      <view class="header-right">
        <view class="name">{{ isSelf ? patientInfo.patientName : userInfo.nickname }}</view>
        <view v-if="isSelf && patientInfo.mobile" class="phone">
            <img class="phone-img" src="https://ainengli.meilianshuke.com/jkhx/raozg/phone-logo.png" alt="" />
            <text class="tel">{{
                stars(patientInfo.mobile)
            }}</text>
        </view>
      </view>
    </view>
    <view class="business">
        <img class="list-bg-img" src="https://ainengli.meilianshuke.com/jkhx/raozg/my-list-bg.png" alt="" />
        <view class="list">
            <view class="item" @tap="checkFamily">
            <view class="left">
                <img class="img" src="https://ainengli.meilianshuke.com/jkhx/raozg/my-switch.png" alt="" />
                <text class="name">家庭成员</text>
            </view>
            <img class="right" src="https://ainengli.meilianshuke.com/jkhx/raozg/more.png" alt="" />
            </view>
            <view class="item" @tap="follow">
            <view class="left">
                <img class="img" src="https://ainengli.meilianshuke.com/jkhx/raozg/my-follows.png" alt="" />
                <text class="name">我的关注</text>
            </view>
            <img class="right" src="https://ainengli.meilianshuke.com/jkhx/raozg/more.png" alt="" />
            </view>
        </view>
        <!-- <view class="list">
            <text class="item" style="text-align: center" @tap="quit">
                退出登录
            </text>
        </view> -->
    </view>
  </view>
</template>

<script setup lang="ts">
import { reactive, ref, getCurrentInstance } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getPatientList } from "@/request/apis/patient.js";
const { proxy }: any = getCurrentInstance();

const patientInfo = ref({})
const userInfo = ref({})
const isSelf = ref(false)

onShow(() => {
    init()
    userInfo.value = proxy.store.userInfo
    console.log('用户信息', userInfo.value)
})

const init = () => {
  getPatientList().then((res) => {
    if (res && res.records && res.records.length > 0) {
        res.records.forEach((val) => {
          if (val.relationship == '01') {
              patientInfo.value = val
              isSelf.value = true
          }
        })
    }
    console.log('就诊人信息', patientInfo.value)
  })
}
const checkFamily = () => {
    proxy.utils.uni.route.go('/pages/patients/index');
}
const follow = () => {
    proxy.utils.uni.route.go('/pages/myFollows/index')
    // proxy.utils.uni.route.go('/pages/myFollows/qrcodeDetail?scene=c1da8ace1eab8900')
}
const stars = (val: string) => {
    return val.substring(0, 3) + '****' + val.substring(7)
}
</script>

<style lang="scss" scoped>
.wrap {
  position: relative;
  overflow: hidden;
  height: 100vh;

  .bg-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: -1;
  }

  .header {
    margin: 48rpx 32rpx;
    display: flex;
    align-items: center;

    .img {
      width: 96rpx;
      height: 96rpx;
      margin-right: 24rpx;
    }

    .login-text {
      font-family: PingFang SC;
      font-weight: 500;
      font-size: 36rpx;
      color: #222222;
      line-height: 50rpx;
    }

    .header-right {
        .name {
            font-size: 36rpx;
            color: #131313;
            font-weight: 700;
            max-width: 500rpx;
            overflow: hidden; //超出的文本隐藏
            text-overflow: ellipsis; //溢出用省略号显示
            white-space: nowrap; //溢出不换行
        }
        .phone {
            margin-top: 8rpx;
            display: flex;
            align-items: center;
            height: 48rpx;
            padding: 0 24rpx;
            background: #FFFFFF;
            border-radius: 24rpx;
            font-weight: 400;
            font-size: 24rpx;
            color: #222222;
            .phone-img {
                width: 28rpx;
                height: 28rpx;
                margin-right: 8rpx;
            }
        }
    }
  }

  .business {
    padding: 32rpx;
    width: 100%;
    position: relative;
    .list-bg-img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 200rpx;
        z-index: 1;
    }
    .list {
        position: relative;
        z-index: 2;
        display: flex;
        flex-direction: column;
        width: 100%;
        background: #fff;
        margin-bottom: 48rpx;
        border-radius: 16rpx;

        .item {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            margin: 0 32rpx;
            height: 108rpx;
            border-bottom: 1rpx solid #e5e6eb;
            &:last-child {
              border: none;
            }

            .left {
                display: flex;
                flex-direction: row;
                align-items: center;
                .img {
                    width: 40rpx;
                    height: 40rpx;
                    margin-right: 16rpx;
                }

                .name {
                    font-family: PingFang SC;
                    font-weight: 400;
                    font-size: 30rpx;
                    color: #222222;
                    line-height: 35rpx;
                }
            }

            .right {
                width: 32rpx;
                height: 32rpx;
            }
        }
    }
  }
}
</style>
